package com.haier.controller.h5;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.haier.service.IHpConstantService;
import com.haier.utils.EmptyUtils;
import com.haier.vo.ResponseVo;

@RestController
@RequestMapping(value = "/hipassjava/h5/constant")
public class H5ConstantContoller {
	private static final Logger logger = LoggerFactory.getLogger(H5ConstantContoller.class);
	@Autowired
	private IHpConstantService iHpConstantService;

	/**
	 * 查询全部
	 */
	@RequestMapping(value = "/findAll", method = RequestMethod.POST)
	public Object findAll(@RequestBody JSONObject params) {
		try {
			return ResponseVo.success(iHpConstantService.findAll(params));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 根据区域id查询审核人
	 */
	@RequestMapping(value = "/findAuditorByAreaId", method = RequestMethod.POST)
	public Object findAuditorByAreaId(@RequestBody JSONObject params) {
		try {
			String areaId = params.getString("areaId");
			if (EmptyUtils.isEmpty(areaId)) {
				return ResponseVo.checkError("区域id不能为空");
			}
			return ResponseVo.success(iHpConstantService.findAuditorByAreaId(params));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}

	/**
	 * 获取随机数(不重复与昨天的)
	 */
	@RequestMapping(value = "/getRandomNumber", method = RequestMethod.GET)
	public Object getRandomNumber() {
		try {
			return ResponseVo.success(iHpConstantService.getRandomNumber());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return ResponseVo.error();
		}
	}
}
